using System;
using Microsoft.WindowsAzure.StorageClient;

namespace AzureContrib.WindowsAzure.StorageClient
{
	/// <summary>
	/// Wrapper around <see cref="CloudQueueMessage"/>
	/// </summary>
	/// <typeparam name="T">The type of payload</typeparam>
	public class CloudQueueMessage<T>
	{
		private readonly CloudQueueMessage cloudQueueMessage;

		/// <summary>
		/// <see cref="CloudQueueMessage{T}"/> is actually wrapping up a <see cref="CloudQueueMessage"/>
		/// </summary>
		/// <param name="cloudQueueMessage">The <see cref="CloudQueueMessage{T}"/></param>
		/// <returns>The <see cref="CloudQueueMessage"/> wrapped up inside.</returns>
		public static implicit operator CloudQueueMessage(CloudQueueMessage<T> cloudQueueMessage)
		{
			return cloudQueueMessage.cloudQueueMessage;
		}

		/// <summary>
		/// <see cref="CloudQueueMessage{T}"/> is actually wrapping up a <see cref="CloudQueueMessage"/>
		/// </summary>
		/// <param name="cloudQueueMessage">The <see cref="CloudQueueMessage{T}"/></param>
		/// <returns>The <see cref="CloudQueueMessage"/> wrapped up inside.</returns>
		public static implicit operator CloudQueueMessage<T>(CloudQueueMessage cloudQueueMessage)
		{
			return new CloudQueueMessage<T>(cloudQueueMessage);
		}

		/// <summary>
		/// Create a typed <see cref="CloudQueueMessage"/> that exposes a deserialized payload
		/// </summary>
		/// <param name="cloudQueueMessage"></param>
		public CloudQueueMessage(CloudQueueMessage cloudQueueMessage)
		{
			this.cloudQueueMessage = cloudQueueMessage;
		}

		/// <summary>
		/// <see cref="CloudQueueMessage.AsBytes"/>
		/// </summary>
		public byte[] AsBytes { get { return cloudQueueMessage.AsBytes; } }

		/// <summary>
		/// <see cref="CloudQueueMessage"/>
		/// </summary>
		public string Id { get { return cloudQueueMessage.Id; } }

		/// <summary>
		/// <see cref="CloudQueueMessage.PopReceipt"/>
		/// </summary>
		public string PopReceipt { get { return cloudQueueMessage.PopReceipt; } }

		/// <summary>
		/// <see cref="CloudQueueMessage.InsertionTime"/>
		/// </summary>
		public DateTime? InsertionTime { get { return cloudQueueMessage.InsertionTime; } }

		/// <summary>
		/// <see cref="CloudQueueMessage.ExpirationTime"/>
		/// </summary>
		public DateTime? ExpirationTime { get { return cloudQueueMessage.ExpirationTime; } }

		/// <summary>
		/// <see cref="CloudQueueMessage.NextVisibleTime"/>
		/// </summary>
		public DateTime? NextVisibleTime { get { return cloudQueueMessage.NextVisibleTime; } }

		/// <summary>
		/// <see cref="CloudQueueMessage.AsString"/>
		/// </summary>
		public string AsString { get { return cloudQueueMessage.AsString; } }

		/// <summary>
		/// <see cref="CloudQueueMessage.DequeueCount"/>
		/// </summary>
		public int DequeueCount { get { return cloudQueueMessage.DequeueCount; } }
	}
}